﻿
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://" + request.getServerName()
				+ ":" + request.getServerPort() + path + "/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>main</title>
<LINK href="./css/style.css" type=text/css rel=stylesheet>
<LINK href="./css/main.css" type=text/css rel=stylesheet>
<script src="./js/WebCalendar.js" type="text/javascript"></script>
<script src="./js/main.js" type="text/javascript"></script>
<script src="./js/jquery-1.7.2.min.js" type="text/javascript"></script>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #5CB7FE;
}
.STYLE1 {font-size: 12px}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: underline;
}
a:active {
	text-decoration: none;
}
.STYLE5 {font-size: 12px; color: #FF0000; }
.STYLE6 {
	font-size: 16px;
	font-weight: bold;
}
-->
 </style>
</head>
<script language="javascript">
	function fn_delete(id){
		if(confirm("你确定要删除该用户吗?")) {
			window.location="userMgmt!delete.action?userId="+id;
		}
	}
	function fn_edit(id, userName, permissions, realName, tel){
		$("#userMgmtAdd tr:first").find("td:eq(6)").hide();
		$("#userMgmtAdd tr:first").find("td:eq(7)").hide();
		$("#userMgmtAdd tr:first").find("td:eq(8)").hide();
		$("#userMgmtAdd tr:first").find("td:eq(9)").hide();
		$("#userMgmtAdd").attr("onSubmit","return checkUpdate()");
		frm = document.getElementById("userMgmtAdd");
		frm.style.display="block";
		frm.bt_smt.value = "更新用户";
		frm.userName.value = userName;
		frm.tel.value = tel;
		frm.realName.value = realName;
		frm.action = "userMgmt!update.action?userId="+id;
		
		var permArr = permissions.split(",");
		for(var i=0; i<permArr.length; i++) {
		    $("#perid_"+permArr[i]).attr("checked","checked");
		}
	}
	
	function fn_changePass(userId, userName) {
		$("#user").html(userName);
		$("#userId").val(userId);
		$("#showdiv").show();    
        $(window).resize(function(){$place ($("showdiv"));}); //调整浏览器大小    
        loadPopup();
	}
	function check() {
		frm = document.getElementById("userMgmt");
		if (frm.className.value == "") {
			frm.className.focus();
			alert("班组名称不能为空");
			return false;
		}
	}
 var popupStatus = 0;
 $(function(){
   var $place = function(selector){//目标居中,目标应为绝对定位
     var $t=( $(window).height()-$(selector).height())/2;
     var $l=( $(window).width()-$(selector).width())/2;    
     $(selector).css({"left":$l+"px","top":$t+"px"});
   }
   
   $("#close").click(function(){
     //仅在开启标志popupStatus为1的情况下去除     
     if(popupStatus==1){
      $("#screen").fadeOut("slow");
      $("#showdiv").fadeOut("slow");
      popupStatus = 0;
     }      
   });
   
   $("#move").mouseover(function(event){
    var _move=false;//移动标记
    var _x,_y;//鼠标离控件左上角的相对位置
    
    $("#move").mousedown(function(e){
     _move=true;     
     _x=e.pageX-parseInt($("#showdiv").css("left"));         
     _y=e.pageY-parseInt($("#showdiv").css("top"));          
    });
        
    $(document).mousemove(function(e){
     if(_move){
      var x=e.pageX - _x;//移动时根据鼠标位置计算控件左上角的绝对位置
      var y=e.pageY - _y;
      $("#showdiv").css({"top":y,"left":x});//控件新位置      
     }
    }).mouseup(function(){
     _move=false;         
    });     
  });
 });
 
 function loadPopup(){    
    //仅在开启标志popupStatus为0的情况下加载 
    if(popupStatus==0){
     $("#screen").css({
      "opacity": "0.5"
     });     
     $("#screen").fadeIn("slow");
     showDivCenter("#showdiv");
      $("body").css({"overflow":"hidden"});
     popupStatus= 1;    
    }
 } 
 
 function showDivCenter(div)
{
	  var wnd = $(window), doc = $(document);
	  var left = doc.scrollLeft();
	  var top = doc.scrollTop();
	 left += (wnd.width() - $(div).width())/2;
	  top += (wnd.height() - $(div).height())/2;
	   $(div).css("position","absolute");
	  $(div).css("top",top);
	  $(div).css("left",left);
	  $(div).fadeIn("slow");
}

function checkPass() {
	if ($("#newPass").val() == "") {
		alert("请输入新密码");
		$("#newPass").focus();
		return false;
	} 
	if ($("#rePass").val() == "") {
	    alert("请输入确认密码");
	    $("#rePass").focus();
	    return false;
	}
	if ($("#rePass").val() != $("#newPass").val()) {
	    alert("新密码与确认密码不符");
	    $("#rePass").focus();
	    return false;
	} 
	return true;
}

function checkAdd() {
	if ($("#addUserName").val() == "") {
	    alert("请输入用户名");
		$("#addUserName").focus();
		return false;
	}
	if ($("#addPassword").val() == "") {
	    alert("请输入密码");
		$("#addPassword").focus();
		return false;
	}
	if ($("#addRepassword").val() != $("#addPassword").val()) {
	    alert("密码与确认密码不符");
		$("#addRepassword").focus();
		return false;
	}
	setPermissions();
	return true;
}

function setPermissions() {
	var perids = "";
	$("input[name='perids']").each(function(){
	    if ("checked" == $(this).attr("checked")) {
	         perids += $(this).val() + ",";
	    }
    });
	$("#permissionsStr").val(perids.substring(0, perids.length - 1));
}

function checkUpdate() {
	if ($("#addUserName").val() == "") {
	    alert("请输入用户名");
		$("#addUserName").focus();
		return false;
	}
	setPermissions();
	return true;
}
</script> 

<body style="overflow-x:hidden">
<table width="100%" height="568" border="0" cellpadding="0"
	cellspacing="0" bordercolor="#D8EDFF">
	<!--DWLayoutTable-->
	<tr>
		<td height="8" colspan="4" valign="top"></td>
		<td width="834" valign="top"></td>
		<td width="5" valign="top"></td>
	</tr>
	<tr>
		<td height="5" colspan="3" align="right" valign="top"><img
			src="images/icon1.jpg" width="6" height="5" /></td>
		<td colspan="2" valign="top"><img src="images/icon2.jpg" width="100%"
			height="5" /></td>
		<td valign="top"><img src="images/icon3.jpg" width="5" height="5" /></td>
	</tr>
	<tr>
		<td width="7" height="523">&nbsp;</td>
		<td width="5" align="right" valign="top" background="images/icon5.jpg"><img
			src="images/icon5.jpg" width="5" height="5" /></td>
		<td colspan="2" valign="top" bgcolor="#D8EDFF">&nbsp;</td>
		<td valign="top" background="images/main_bg.png">
		
		<table width="100%" border="0" cellpadding="0" cellspacing="0"
			bgcolor="#D8EDFF">
			<!--DWLayoutTable-->
			<tr>
				<td height="30" colspan="3" valign="middle"><span class="STYLE1">&nbsp;[用户管理]</span></td>
				<td width="29">&nbsp;</td>
			</tr>
			<tr>
				<td height="59" colspan="3" align="center" valign="middle" class="STYLE6">用&nbsp;&nbsp; 户&nbsp;&nbsp; 管&nbsp;&nbsp;理</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td width="90" height="345">&nbsp;</td>
				<td width="90%" valign="top">
				<s:if test="msg != null"> 
   				 	<div id="msg">
   				 		<table>
   				 			<tr>
   				 				<td width="1%"><img src="images/error.gif"></td>
   				 				<td>&nbsp;&nbsp;<span id="msgText"><s:property value="msg"/></span></td>
   				 				<td width="1%"><img src="images/close.png" alt="关闭" style="cursor:pointer;" onclick="closeMsgBox()"/></td>
   				 			</tr>
   				 		</table>
   				 	</div>
					</s:if>
		    <form name="userMgmtAdd" id="userMgmtAdd" method="post" action="userMgmt!add.action" onSubmit="return checkAdd();">
			 <fieldset>
   				 <legend class="STYLE1"><img alt="管理" src="images/edit.gif"/> &nbsp;&nbsp;用户基本信息管理</legend>
					<table>
						<tr>
						  <td width="90" align="right" valign="middle"><span class="STYLE1">用户名：</span></td>
						  <td width="100" valign="middle"><input name="userName" id="addUserName" type="text" size="16" maxlength="20" style="width:90px; height:18px;" value=""></td>
					  	  <td width="90" align="right" valign="middle"><span class="STYLE1">真实姓名：</span></td>
						  <td width="100" valign="middle"><input name="realName" id="addRealName" type="text" size="16" maxlength="20" style="width:90px; height:18px;" value=""></td>
						   <td width="90" align="right" valign="middle"><span class="STYLE1">联系电话：</span></td>
						   <td width="100" valign="middle"><input name="tel" id="addTel" type="text" size="16" maxlength="20" style="width:90px; height:18px;" value=""></td>
						   <td width="90" align="right" valign="middle"><span class="STYLE1">密码：</span></td>
						   <td width="100" valign="middle"><input name="password" id="addPassword" type="password" size="16" maxlength="20" style="width:90px; height:18px;" value=""></td>
						   <td width="90" align="right" valign="middle"><span class="STYLE1">确认密码：</span></td>
						   <td width="100" valign="middle"><input name="repassword" id="addRepassword" type="password" size="16" maxlength="20" style="width:90px; height:18px;" value=""></td>
					  	</tr>					  	
				  </table>
				  <p/>
				  <div class="STYLE1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用户权限:</div>
					<table>
					    <s:iterator value="permissions">
						<tr>
						  <td width="90" align="right" valign="middle"><input name="perids" id="perid_<s:property value="id"/>" type="checkbox" value="<s:property value="id"/>"></td>
					  	  <td width="90" align="right" valign="middle"><span class="STYLE1"><s:property value="permission"/></span></td>
					  	</tr>
					  	</s:iterator>
					  	<tr>
					  		<td>
					  		<input name="permissionsStr" id="permissionsStr" type="hidden"/>
					  		<input name="bt_smt" id="bt_smt" type="submit" class="btn1_mouseout" onMouseOver="this.className='btn1_mouseover'" onMouseOut="this.className='btn1_mouseout'" value="新增用户 "></td>
					  	</tr>					  	
				  </table>
		  	 </fieldset>
		  </form>
		  </div>
				<table width="100%" border=0 cellpadding=0 cellspacing=1
					bgcolor=5cb7fe>
					<!--DWLayoutTable-->
					<tr>
						<td width="30" height="25" align="center"
							bgcolor="#D8EDFF"><span class="STYLE1">序号 </span></td>
						<td width="107" height="25" align="center"
							bgcolor="#D8EDFF"><span class="STYLE1">用户名 </span></td>
						<td width="93" align="center" valign="middle"
							bgcolor="#D8EDFF"><span class="STYLE1">真实姓名</span></td>
						<td width="93" align="center" valign="middle"
							bgcolor="#D8EDFF"><span class="STYLE1">联系电话</span></td>
						<td width="93" align="center" valign="middle"
							bgcolor="#D8EDFF"><span class="STYLE1">操作</span></td>
					</tr>
					<s:iterator value="users" status="cs">
					<tr>
					  <td height="25" align="center" valign="middle"
							bgcolor="#D8EDFF"><span class="STYLE1"><s:property value="#cs.count"/></span></td>
					  <td height="25" align="center" valign="middle"
							bgcolor="#D8EDFF"><span class="STYLE1"><s:property value="userName"/></span></td>
					  <td align="center" valign="middle"
							bgcolor="#D8EDFF"><span class="STYLE1"><s:property value="realName"/></span></td>
					  <td align="center" valign="middle"
							bgcolor="#D8EDFF"><span class="STYLE1"><s:property value="Tel"/></span></td>
					  <td align="center" valign="middle"
							bgcolor="#D8EDFF"><span class="STYLE1">
							<a href="javascript:void(0)"><img src="images/password.png" onclick='fn_changePass(<s:property value="userId"/>,"<s:property escape="0" value="userName"/>")' /></img></a></span>&nbsp;&nbsp;
							<a href="javascript:void(0)"><img src="images/edit.gif" onclick='fn_edit(<s:property value="userId"/>,"<s:property escape="0" value="userName"/>", "<s:property value="permissions"/>", "<s:property escape="0" value="realName"/>", "<s:property value="tel"/>")' /></img></a>&nbsp;&nbsp;
							<a href="javascript:void(0)"><img src="images/delete.gif" onclick='fn_delete(<s:property value="userId"/>,"<s:property escape="0" value="userName"/>")' /></img></a></span></td>
				  </tr>
				  </s:iterator>
				</table>
				</td>
				<td width="50">&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
</table>
		</td>
		<td valign="top" background="images/icon6.jpg"><img
			src="images/icon6.jpg" width="5" height="100" /></td>
	</tr>

	<tr>
		<td height="5"></td>
		<td valign="top"><img src="images/icon7.jpg" width="5" height="5" /></td>
		<td colspan="3" valign="top"><img src="images/icon8.jpg" width="100%"
			height="5" /></td>
		<td valign="top"><img src="images/icon9.jpg" width="5" height="5" /></td>
	</tr>
	<tr>
		<td height="2"></td>
		<td></td>
		<td width="1"></td>
		<td width="6"></td>
		<td></td>
		<td></td>
	</tr>
</table>
<div id="screen"><!--该DIV用于锁屏--></div>
<div id="showdiv">
	<form name="userMgmtChangePass" id="userMgmtChangePass" method="post" action="userMgmt!changePassByAdmin.action" onSubmit="return checkPass();">
	<table style="width:100%">
		<tr>
			<td colspan="2" style="text-align:center;"><span id="move">修改用户 &nbsp;<span id="user"></span> &nbsp;的密码</span></td>
			<td><img id="close" src="./images/close.png" style="cursor:pointer;"></td>
		</tr>
		<tr>
			<td class="STYLE1" style="width:100px;text-align:right;">新密码：</td>
			<td><input type="password" id="newPass" name="password" style="width:80px; margin:6 6 3 0px;text-align:left;"></td>
			<td><input type="hidden" id="userId" name="userId" style="width:80px; margin:6 6 3 0px;text-align:left;"></td>
		</tr>
		<tr>
			<td class="STYLE1" style="width:100px;text-align:right;">确认密码：</td>
			<td><input type="password" id="rePass" style="width:80px; margin-bottom:3 6 10 6px;text-align:left;"></td>
			<td></td>
		</tr>
		<tr>
			<td colspan="3"><div style="text-align:center; margin-top:4px;"><input type="submit" id="changePassBt" class="btn1_mouseout" value="提 交"/></div></td>
		</tr>
    </table>
    </form>
</div>
</body>
</html>
